package operate.node;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;

/**
 * @author m0v1
 * @date 2021年09月07日 8:06 上午
 */
public class GetNodeData extends AbstractNodeOperation {
    @Override
    public void process(WatchedEvent watchedEvent) {
        // 监听连接事件
        if (watchedEvent.getState() == Event.KeeperState.SyncConnected) {
            try {
                byte[] data1 = zooKeeper.getData(
                        "/zk-create-permanent-node-by-api",
                        false,
                        // 节点状态信息,null表示最新版本的状态
                        null
                );


                // byte[] data2 = zooKeeper.getData(
                //         "/zk-create-permanent-sequential-node-by-api",
                //         false,
                //         null
                // );

                byte[] data3 = zooKeeper.getData(
                        "/zk-create-ephemeral-node-by-api",
                        false,
                        null
                );

                // byte[] data4 = zooKeeper.getData(
                //         "/zk-create-ephemeral-sequential-node-by-api",
                //         false,
                //         null
                // );

                System.out.println("data of node:/zk-create-permanent-node-by-api is :" + new String(data1));
                // System.out.println("data of node:/zk-create-permanent-sequential-node-by-api is :" + new String(data2));
                System.out.println("data of node:/zk-create-ephemeral-node-by-api is :" + new String(data3));
                // System.out.println("data of node:/zk-create-ephemeral-sequential-node-by-api is :" + new String(data4));
            } catch (KeeperException | InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
